package com.party.core.service.photo.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.core.dao.read.photo.PhotosTagReadDao;
import com.party.core.dao.write.photo.PhotosTagWriteDao;
import com.party.core.model.BaseModel;
import com.party.core.model.photo.PhotosTag;
import com.party.core.service.photo.IPhotosTagService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @Description:
 * @Author: yangshoukun
 * @Date: 2018/5/30 14:28
 */
@Service
public class PhotosTagService implements IPhotosTagService {

    @Autowired
    private PhotosTagReadDao photosTagReadDao;

    @Autowired
    private PhotosTagWriteDao photosTagWriteDao;

    @Override
    public String insert(PhotosTag photosTag) {
        BaseModel.preInsert(photosTag);
        boolean result = photosTagWriteDao.insert(photosTag);
        if (result){
            return photosTag.getId();
        }
        return null;
    }

    @Override
    public boolean update(PhotosTag photosTag) {
        return photosTagWriteDao.update(photosTag);
    }

    @Override
    public boolean deleteLogic(String id) {
        if (Strings.isNullOrEmpty(id)){
            return false;
        }
        return photosTagWriteDao.deleteLogic(id);
    }

    @Override
    public boolean delete(String id) {
        if (Strings.isNullOrEmpty(id)){
            return false;
        }
        return photosTagWriteDao.delete(id);
    }

    @Override
    public boolean batchDeleteLogic(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)){
            return false;
        }
        return photosTagWriteDao.batchDeleteLogic(ids);
    }

    @Override
    public boolean batchDelete(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)){
            return false;
        }
        return photosTagWriteDao.batchDelete(ids);
    }

    @Override
    public PhotosTag get(String id) {
        return photosTagReadDao.get(id);
    }

    @Override
    public List<PhotosTag> listPage(PhotosTag photosTag, Page page) {
        return photosTagReadDao.listPage(photosTag, page);
    }

    @Override
    public List<PhotosTag> list(PhotosTag photosTag) {
        return listPage(photosTag, null);
    }

    @Override
    public List<PhotosTag> batchList(Set<String> ids, PhotosTag photosTag, Page page) {
        return null;
    }

    @Override
    public List<PhotosTag> webList(Map<String, Object> map, PhotosTag photosTag, Page page) {
        return photosTagReadDao.webList(map, photosTag, page);
    }

    @Override
    public PhotosTag findByName(PhotosTag tag) {
        return photosTagReadDao.findByName(tag);
    }

    @Override
    public List<PhotosTag> listByImgId(PhotosTag photosTag, String imgId) {
        return photosTagReadDao.listByImgId(photosTag, imgId);
    }
}
